<%@ include file="/taglibs.jsp"%>

<head>
    <title><fmt:message key="categoryForm.title"/></title>
</head>

<p><fmt:message key="categoryForm.title"/></p>
<s:form name="categoryForm" action="saveCategory" method="post" validate="true">
<s:hidden name="cateId" value="%{entity.id}"/>
<tr>
	<td>
		<s:text name="category.categoryName"></s:text>
        <span class="required">*</span>:
    </td>
    <td>
    	<s:textfield maxlength="250" name="categoryName" required="true" theme="simple" size="70"/>
    </td>
</tr>
<tr>
	<td>
		<s:text name="category.shortName"></s:text>
        <span class="required">*</span>:
    </td>
    <td>
    	<s:textfield maxlength="50" name="shortName" required="true" theme="simple" size="50"/>
    </td>
</tr>
<tr>
	<td>
		<s:text name="category.code" ></s:text>
        <span class="required">*</span>:
    </td>
    <td>
    	<s:textfield maxlength="30" name="code"  theme="simple" size="10" required="true"/>
   </td>
</tr>  

<s:select required="true" key="category.field" cssStyle="max-width: 500px !important;" name="fieldId" list="fields" listKey="id" listValue="name" headerKey="%{getText('select.default.key')}" headerValue="%{getText('select.default.value')}"></s:select>

<s:select required="true" key="category.workflow" cssStyle="max-width: 500px !important;" name="workflowId" list="workflows" listKey="id" listValue="name" headerKey="%{getText('select.default.key')}" headerValue="%{getText('select.default.value')}"></s:select>

<tr>
	<td>
		<s:text name="category.description"></s:text>
    </td>
    <td>
    	<s:textarea  name="description" theme="simple" cols="60" rows="5"></s:textarea>
   </td>
</tr>
	<!-- Mau Bien Nhan -->
	<s:select required="true" key="category.report" cssStyle="max-width: 500px !important;" name="reportId" list="lstReport" listKey="id" listValue="reportName" headerKey="%{getText('select.default.key')}" headerValue="%{getText('select.default.value')}"></s:select>
	
	<!-- Mau KSTD -->
	<s:select required="true" key="category.voucher" cssStyle="max-width: 500px !important;" name="voucherId" list="lstReport" listKey="id" listValue="reportName" headerKey="%{getText('select.default.key')}" headerValue="%{getText('select.default.value')}"></s:select>
	
	<s:checkbox name="isViewOnnet" key="category.isViewOnnet" tooltip="category.isViewOnnet"></s:checkbox>
	<s:checkbox name="isRegisterOnnet" key="category.isRegisterOnnet"></s:checkbox>
	
<tr>
	<td>
		<s:text name="category.feeNew"></s:text>
    </td>
    <td>
    	<s:textfield maxlength="30" name="feeNew" required="true"  theme="simple" size="10" /><s:text name="category.currency"/>
   </td>
</tr>
<tr>
	<td>
		<s:text name="category.feeChange"></s:text>
    </td>
    <td>
    	<s:textfield maxlength="30" name="feeChange" required="true"  theme="simple" size="10"/><s:text name="category.currency"/>
   </td>
</tr>
<tr>
	<td>
		<s:text name="category.processTime"></s:text>
    </td>
    <td>
    	<s:textarea  name="processTime" theme="simple" cols="60" rows="5"></s:textarea>
   </td>
</tr>
	
<tr>
    <td colspan="2">
    	<button type="submit" class="button" name="save" onclick="this.blur()" >
			<fmt:message key="button.save.title"></fmt:message>
			<img src="${ctx}/images/btn_save.png" align="left" height="20" width="20">
		</button>
	    <c:if test="${not empty cateId}">
	    	<button type="submit" class="button" name="delete" onclick="return confirm('<fmt:message key="message.delete.confirm"></fmt:message>')">
				<fmt:message key="button.delete.title"></fmt:message>
				<img src="${ctx}/images/btn_delete.png" align="left" height="20" width="20">
			</button>
    	</c:if>
        <button type="submit" class="button" name="cancel" onclick="form.onsubmit=null"">
			<fmt:message key="button.cancel.title"></fmt:message>
			<img src="${ctx}/images/btn_cancel.png" align="left" height="20" width="20">
		</button>
    </td>
</tr>

</s:form>

<c:if test="${not empty cateId}">
<display:table name="files" class="table" requestURI="" id="files" export="false" pagesize="10">
    <display:column property="attachFileName" sortable="false" href="edit_attach_file.html" media="html"
        paramId="id" paramProperty="id" titleKey="category.attachfiles" escapeXml="true"/>
</display:table>
<button onclick="location.href='edit_attach_file.html?cateId=${cateId}&fieldId=${fieldId}'"  style="text-align: center;">
	<fmt:message key="button.add.title"></fmt:message>
	<img src="${ctx}/images/btn_add.png" align="left" height="20" width="20">
</button>
</c:if>

<script type="text/javascript">highlightTableRows("files");</script>
<script type="text/javascript">

$(document).ready(function() {
	$('#save').click(function(){
		$.blockUI({ message: ajaxAnimation });
		$.ajax({
		  type: 'POST',
		  url: $('form').attr('action') + '?struts.enableJSONValidation=true&struts.validateOnly=true',
		  data: $('form').serialize(),
		  success: function(data){
			 var errorsObject = $.StrutsUtils.getValidationErrors(data);
			 if(errorsObject.fieldErrors) {
				 $.StrutsUtils.showValidationErrors($('form'), errorsObject);
		     } else if(errorsObject.errors) {
				 $.StrutsUtils.showValidationErrors($('form'), errorsObject);
		     } else {
		       //good to go, regular submit
		       $('form').submit();
		     }
		  },
		  dataType: "text/html"
		});
	});
});

</script>
